using System;
using System.Runtime.Serialization;

namespace Needle.Utils.Parser
{
    /// <summary></summary>
    [Serializable]
    public class ParseException : Exception
    {
        /// <summary></summary>
        public ParseException(string message)
            : this(-1, -1, message)
        { }
        /// <summary></summary>
        public ParseException(int line, int column, string message)
            : base(message)
        {
            _Line = line;
            _Column = column;
        }
        /// <summary></summary>
        public ParseException(StringToken token, string message)
            : base(String.Format("{0}: {1}",token, message))
        {
            _Line = token.Line;
            _Column = token.Column;
        }

        private int _Line;
        /// <summary></summary>
        public int Line
        {
            get { return _Line; }
        }

        private int _Column;
        /// <summary></summary>
        public int Column
        {
            get { return _Column; }
        }
        /// <summary></summary>
        protected ParseException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _Line = info.GetInt32("_Line");
            _Column = info.GetInt32("_Column");
        }
        /// <summary></summary>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("_Line", _Line);
            info.AddValue("_Column", _Column);
        }
    }
}
